home *** CD-ROM | disk | FTP | other *** search
- Path: sn.no!orjarive
- From: jakob.rivertz@aftenposten.no (Jakob Rivertz)
- Newsgroups: comp.sys.amiga.programmer
- Subject: Re: x ^= y ^= x ^= y;
- Date: Thu, 29 Feb 96 06:52:35 GMT
- Organization: Aftenposten A/S
- Message-ID: <4h3ivp$966@hasle.sn.no>
- References: <1286.6624T1439T237@cs.ruu.nl> <3Du8y*20g@yaps.rhein.de> <3132C4BE.2D60@cs.ruu.nl>
- NNTP-Posting-Host: gatekeeper.aftenposten.no
- X-Newsreader: News Xpress 2.0 Beta #0
-
- In article <3132C4BE.2D60@cs.ruu.nl>, Wessel Dankers <wsldanke@cs.ruu.nl>
- wrote:
- >Arno Eigenwillig wrote:
- >> In article <1286.6624T1439T237@cs.ruu.nl>, Wessel Dankers writes:
- >> > Which can of course be rewritten as:
- >> > x ^= y;
- >> > y ^= x;
- >> > x ^= y;
- >> Yes.
- >> > or if you want it real fancy:
- >> > x ^= y ^= x ^= y;
- >> No. Reread your C text book and find out about sequence points, side
- >> effects, and which combinations of them are not allowed.
- >If you would have taken a quick peek yourself you would have seen that an
- >assignment has a return-value of itself. Anyway, I tested it and it worked.
-
- Leave this guy alone, everyone. It's is a troll.
-
- For those of you who have been misleaden by these posts, do get the
- comp.lang.c-faq, read questions 4.1 through 4.6, and 6.1 (which discusses
- this very example). You are not allowed to modify the same value twice
- between sequence points. Sequence points are implied by `&&', `||', `,',
- `? :' and `;'. For example:
-
- <never use these>
- a[i] = i++;
- j = i++ * i++;
- x ^= y ^= x ^= y;
- i = ++i;
- </never use these>
-
- all invoke undefined behaviour. The compiler can do _anything_, when these
- constructs are used. Yes, it may even generate the /correct/ code, but it
- may also `format your harddrive' (see recent discussions on comp.lang.c).
- Even if it /works/ on your compiler, there is no guarantee that it works
- on other compilers, or even on future versions of your compiler.
-
- PS: You may use the eor-trick with the blitter, as you then _specify_ the
- order of evaluation. It works, but is slower than the copy-temp scheme.
- The eor-trick uses (2reads + 1write) per element, while the copy-temp
- scheme uses (1read + 1write) per element. Also, "x^=y; y^=x; x^=y;" works
- (the semi-colons act as sequence points).
-
- --
- Jakob <jakob.rivertz@aftenposten.no>
-